//=============================================================================
// tfGuardProj.
//=============================================================================
class tfGuardProj extends TFProjectile;

var() sound HitSound;
var Actor Seeking;
var float seekadjust;
var vector InitialDir;

replication
{
    reliable if( bNetInitial && (Role==ROLE_Authority) )
        seekadjust, Seeking, InitialDir;
}

simulated function PostBeginPlay()
{
    local Rotator R;

	Super.PostBeginPlay();

	Velocity = Vector(Rotation);
    Velocity *= Speed+rand(500);

    R = Rotation;
    R.Roll = Rand(65536);
    SetRotation(R);

    PlaySound(sound'TFMedia.tfGuardShot', SLOT_None,1);
    Spawn(class'TaskForces.tfProtMuz');

	setTimer(0.1,true);
}

simulated function Timer()
{
    local vector ForceDir, seekloc;
    local float VelMag;

    if ( InitialDir == vect(0,0,0) )
        InitialDir = Normal(Velocity);

    if (Seeking != None)
    {
		//seekloc= seeking.Location + FMin(0.1+frand()*0.9, 0.5 + 1.3 * FRand()) * (seeking.Velocity * VSize(seeking.Location - location)/vsize(velocity));
        seekloc=seeking.Location+seekadjust*vect(0,0,1);
        seekloc+=frand()*(seeking.velocity*(vsize(seeking.location-location)/vsize(velocity)));

        ForceDir = Normal(seekloc - Location);

		if( (ForceDir dot InitialDir) > 0 )
		{
			VelMag = VSize(Velocity);

			ForceDir = Normal(ForceDir * 0.5 * VelMag + Velocity);
			Velocity =  VelMag * ForceDir;
		}
		SetRotation(rotator(Velocity));
    }
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
    HurtRadius(40, 150, MyDamageType, 20000, HitLocation);

    if ( EffectIsRelevant(Location,false) )
	{
        Spawn(class'Taskforces.tfGuardProjSparks',,, HitLocation, rotator(HitNormal));
	}
    PlaySound(HitSound);
	Destroy();
}

simulated function ProcessTouch (Actor Other, vector HitLocation)
{
//    local Vector X, RefNormal, RefDir;
    if(other==none) return;
    if(tfguardian(other)!=none && tfguardian(other).MyTeam==0) return;
    if(BigShieldSphere(other)!=none && BigShieldSphere(other).Shield!=none && BigShieldSphere(other).Shield.myteam==0) return;

    //else if(pawn(other)!=none && pawn(other).playerreplicationinfo!=none &&
    //     pawn(other).playerreplicationinfo.team.teamindex==tfStation(owner).myteam) return;

    if ( !Other.IsA('Projectile') || Other.bProjTarget )
	{
		instigator=none;
		setowner(none);

        Explode(HitLocation, vector(rotation));
	}
}

defaultproperties
{
     HitSound=Sound'TFMedia.Buildings.tfGProjHit'
     Speed=3000.000000
     MaxSpeed=3500.000000
     Damage=40.000000
     MomentumTransfer=20000.000000
     MyDamageType=Class'taskforces.DamTypeGuardProjR'
     ExplosionDecal=Class'XEffects.LinkBoltScorch'
     DrawType=DT_StaticMesh
     StaticMesh=StaticMesh'TFMedia.fX.tfGProjRed'
     AmbientSound=Sound'WeaponSounds.LinkGun.LinkGunProjectile'
     LifeSpan=25.000000
     PrePivot=(X=15.000000)
     AmbientGlow=217
     Style=STY_Additive
     SoundVolume=255
     SoundRadius=50.000000
     bFixedRotationDir=True
     RotationRate=(Roll=60000)
     ForceType=FT_Constant
     ForceRadius=30.000000
     ForceScale=5.000000
}
